    #include "btform.h"
#include "ui_btform.h"
#include<QMouseEvent>
#include<QDebug>
#include<QEvent>
#include<QObject>
#include<QPropertyAnimation>

btForm::btForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::btForm)
{
    ui->setupUi(this);
    //将所有的动画先隐藏起来
    ui->lineBox->hide();
    ui->btStyle->setAttribute(Qt::WA_Hover, true);

    //增加lineBox的动画属性
    addAnimation(ui->line1,1500,QRect(7,27,2,0),QRect(7,7,2,20));
    addAnimation(ui->line2,1600,QRect(16,27,2,0),QRect(16,7,2,20));
    addAnimation(ui->line3,1700,QRect(25,27,2,0),QRect(25,7,2,20));
    addAnimation(ui->line4,1800,QRect(34,27,2,0),QRect(34,7,2,20));
}

btForm::~btForm()
{
    delete ui;
}

void btForm::addAnimation(QObject *obj,int sec,QRect rect1,QRect rect2)
{
    //创建对象
    QPropertyAnimation* animation=new QPropertyAnimation(obj,"geometry",this);
    animation->setDuration(sec);//设置动画1个周期所需要的时间
    //设置动画的初始状态与中间状态
    animation->setKeyValueAt(0,rect1);
    animation->setKeyValueAt(0.5,rect2);
    animation->setKeyValueAt(1,rect1);
    animation->setLoopCount(-1);
    animation->start();

}

void btForm::ShowAnimation()
{
    ui->lineBox->show();
}

void btForm::hideAnimation()
{
    ui->lineBox->hide();
}


void btForm::clearColor()
{
   ui->btStyle->setStyleSheet("#btStyle:hover{ background:#D8D8D8;} ");
}

int btForm::getId()
{
    return _pageId;
}



void btForm::setIconAndText(const QString &Icon, const QString &Text,int pageId)
{
    //设置图片
    ui->btIcon->setPixmap(QPixmap(Icon));
    //设置文本
    ui->btText->setText(Text);

    //设置id
    _pageId=pageId;
}

void btForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    //1:点击的时候修改颜色,表示选中了该btForm
    ui->btStyle->setStyleSheet("background:rgb(30,206,154);color:#F6F6F6;");
    //2:修改对应的层叠窗口(主页面去修改)
    //发送信号给主界面
    emit MouseClicked(_pageId);

}

void btForm::test()
{
    ui->btIcon->setStyleSheet("background-position:center center");
    ui->btText->setStyleSheet("background-position:center center");
}




